<html xmlns="http://www.w3.org/1999/xhtml">
  
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
  <title>Medium Python Particles</title>
  <script type="text/javascript">window.DLR = {}; DLR.path = "/dlr";</script>
  <script src="/dlr/dlr.js" type="text/javascript"></script>
</head>

<body>

  <script type="text/python" class="page">
      from System import * # for Convert
      from System.Windows.Controls import UserControl, Canvas
      from System.Windows import * # for NameProperty
      from System.Windows.Shapes import * # exposes Rectangle to scope since not added by default
      from System.Windows.Media.Animation import * # exposes Storyboard
      #from System.Windows.Media.Imaging import * # for bitmap
      from System.Diagnostics import * # enables outputing to a debug window
      from System.Net import * # for WebClient
      from System.Windows.Resources import * # for WebClient
      from System.Windows.Markup import * # for XamlReader
      from Microsoft.Scripting.Silverlight.DynamicApplication import MakeUri

      layoutRoot = me.LayoutRoot

      _dot = None

      #
      # define class that procedurally creates Tile code instead of XAML
      #
      class Dot(UserControl):
          def __init__(self, xaml):
              self.xaml = xaml
          
              self.Content = XamlReader.Load(self.xaml)
              
              def sbDrop_Completed(sender, e): # Storyboard is define in XAML
                  self.Parent.Children.Remove(self);
                  
              self.Content.sbDrop.Completed += sbDrop_Completed
                  
              self.Content.sbDrop.Begin();
              
          def SetX(self, value):
              self.SetValue(Canvas.LeftProperty, Convert.ToDouble(value))
          def GetX(self):
              return self.GetValue(Canvas.LeftProperty)
          X = property(GetX, SetX)
          
          def SetY(self, value):
              self.SetValue(Canvas.TopProperty, Convert.ToDouble(value))
          def GetY(self):
              return self.GetValue(Canvas.TopProperty)
          Y = property(GetY, SetY)
          
      def DotLoaded(sender, e):
          global _dot
          _dot = e.Result
          Main()
          
      def Page_MouseMove(sender, e):
          global layoutRoot
          global _dot
          d = Dot(_dot)
          d.X = e.GetPosition(layoutRoot).X;
          d.Y = e.GetPosition(layoutRoot).Y;
          layoutRoot.Children.Add(d);

      def LoadDot():
          client = WebClient()
          client.DownloadStringCompleted += DotLoaded
          client.DownloadStringAsync(MakeUri("dot2.xaml"))
          
      def Main():
          layoutRoot.MouseMove += Page_MouseMove 

      LoadDot()
  </script>

  <!-- 
    The following commented line of code is equivalent to the inline XAML
    and we recommend doing it this way. Only caveat, if you link to a XAML
    file, you'll be able to view the page correctly only through a server 
    (e.g. apache or IIS) because of security sandbox reasons.
  -->

  <!--<script src="page2.xaml" id="page" type="application/xml+xaml" width="600" height="300"></script>-->
  
  <script id="page" type="application/xml+xaml" width="600" height="300">
  
      <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="600" Height="300">
        <Canvas x:Name="LayoutRoot" Background="#333333">
          <TextBlock Canvas.Left="10" Canvas.Top="10" Text="Move the mouse on the stage to draw your dots..." Foreground="White"></TextBlock>
        </Canvas>
      </UserControl>
  
  </script>
    
</body>
</html>



    
